package com.hns.can.common.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.vo.AlarmSettingCacheVo;
import com.hns.can.common.vo.SysCacheVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 缓存设置
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class SysCacheService extends CommonService {
    
    @Cacheable(value=GlobalConst.CACHE_KEY_SYS_CODE, key="#corpId")
    public Object setSysCodeCache(String corpId){
        Map<String, List<SysCacheVo>> result = new HashMap<String, List<SysCacheVo>>();
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setSysCodeCache", corpId), SysCacheVo.class);
        if(PubUtil.isNotEmpty(list)){
        	for (SysCacheVo entity : list) {
        		String code = entity.getCodeClId();
        		List<SysCacheVo> temp = result.get(code);
        		if(temp == null){
        			temp = new ArrayList<SysCacheVo>();
        			result.put(code, temp);
        		}
        		temp.add(entity);
        	}
        }
        return result;
    }
    
    @Cacheable(value=GlobalConst.CACHE_KEY_SYS_ROLE, key="#corpId")
    public Object setSysRoleCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setSysRoleCache", corpId), SysCacheVo.class);
        return list;
    }
    
//    @CacheEvict(value=GlobalConst.CACHE_KEY_SYS_ROLE, key="#corpId")
//    public void cleanSysRoleCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_SYS_ACCOUNT, key="#corpId")
    public Object setSysAccountCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setSysAccountCache", corpId), SysCacheVo.class);
        return list;
    }
    
//    @CacheEvict(value=GlobalConst.CACHE_KEY_SYS_ACCOUNT, key="#corpId")
//    public void cleanSysAccountCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_ORGAN, key="#corpId")
    public Object setBaseOrganCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseOrganCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @CacheEvict(value=GlobalConst.CACHE_KEY_BASE_ORGAN, key="#corpId")
    public void cleanBaseOrganCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_SYS_CORP)
    public Object setSysCorpCache(){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setSysCorpCache"), SysCacheVo.class);
        return list;
    }
    
//    @CacheEvict(value=GlobalConst.CACHE_KEY_SYS_CORP)
//    public void cleanSysCorpCache(){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_CAR_INFO, key="#corpId")
    public Object setBaseCarInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseCarInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @CacheEvict(value=GlobalConst.CACHE_KEY_BASE_CAR_INFO, key="#corpId")
    public void cleanBaseCarInfoCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_LINE_INFO, key="#corpId")
    public Object setBaseLineInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseLineInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @CacheEvict(value=GlobalConst.CACHE_KEY_BASE_LINE_INFO, key="#corpId")
    public void cleanBaseLineInfoCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_DRV_INFO, key="#corpId")
    public Object setBaseDrvInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseDrvInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @CacheEvict(value=GlobalConst.CACHE_KEY_BASE_DRV_INFO, key="#corpId")
    public void cleanBaseDrvInfoCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_UPG_EQMT_VRSN_MANAGE_INFO, key="#corpId")
    public Object setUpgEqmtVrsnManageInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setUpgEqmtVrsnManageInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_EQMT_INFO, key="#corpId")
    public Object setBaseEqmtInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseEqmtInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    @CacheEvict(value=GlobalConst.CACHE_KEY_BASE_EQMT_INFO, key="#corpId")
    public void cleanBaseEqmtInfoCache(String corpId){}
    
    @Cacheable(value=GlobalConst.CACHE_KEY_BASE_STN_INFO, key="#corpId")
    public Object setBaseStnInfoCache(String corpId){
        List<SysCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setBaseStnInfoCache", corpId), SysCacheVo.class);
        return list;
    }
    
    
    //=======================
    @Cacheable(value=GlobalConst.CACHE_ALARM_TIME_SETTING, key="#corpId")
    public Object setAlarmTimeSetCache(String corpId){
        List<AlarmSettingCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setAlarmTimeSetCache", corpId), AlarmSettingCacheVo.class);
        return list;
    }
    
    @Cacheable(value=GlobalConst.CACHE_ALARM_FAULT_SETTING, key="#corpId")
    public Object setAlarmFaultSetCache(String corpId){
        List<AlarmSettingCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setAlarmFaultSetCache", corpId), AlarmSettingCacheVo.class);
        return list;
    }
    
    @Cacheable(value=GlobalConst.CACHE_ALARM_UNSAFE_SETTING, key="#corpId")
    public Object setAlarmUnsafeSetCache(String corpId){
        List<AlarmSettingCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setAlarmUnsafeSetCache", corpId), AlarmSettingCacheVo.class);
        return list;
    }
    
    @Cacheable(value=GlobalConst.CACHE_ALARM_SPEED_SETTING, key="#corpId")
    public Object setAlarmSpeedSetCache(String corpId){
        List<AlarmSettingCacheVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("sysCache.setAlarmSpeedSetCache", corpId), AlarmSettingCacheVo.class);
        return list;
    }
    
    
}
